<template>
    <el-table
    :data="tableData"
    border
    style="width: 100%"
    >
    <el-table-column
      fixed
      prop="name"
      label="姓名"
      width="150">
    </el-table-column>
    <el-table-column
      prop="account"
      label="账号"
      width="120">
    </el-table-column>
    <el-table-column
      prop="phone"
      label="电话号"
      width="120">
    </el-table-column>
    <el-table-column
      prop="password"
      label="密码"
      width="120">
    </el-table-column>
    <el-table-column
      prop="role"
      label="角色"
      width="300">
    </el-table-column>
    <el-table-column
      prop="id"
      label="id"
      width="300">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template #default="scope" >
        <el-button  icon="el-icon-edit" type="text" @click="exit(scope.$index)"  size="small">编辑</el-button>
        <el-button  icon="el-icon-delete" type="text" @click="removeById(scope.$index)" size="small">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
  import qs from 'qs'
import { id } from 'element-plus/es/locale';
  export default {
    
    data() {
      return {
        tableData: [],
      } ;
    },
    methods: {
       User(){
        this.axios.get('http://127.0.0.1:9090/user/selectAll').then((result) => {
            // console.log(result.data.data.records[0])
            this.tableData=result.data.data.records
        }).catch((err) => {
            
        });
        },


        removeById(index) {

          // console.log("123")
          var id=this.tableData[index].id
          console.log(id)
          let params=qs.stringify({
            id:id
          })
          // console.log(id)
         
          this.axios.post('http://127.0.0.1:9090/user/deleteById',params).then((result)=>{
            console.log(result.data.code)
            // if(result.data.code=0){
              //  alert("删除成功")
               this.User()
            // }         
          }).catch((err)=>{
          })
          // console.log(id)
        
      },
      exit(index){
        let id =this.tableData[index].id
        // console.log(id)
        this.$router.push({
          path: '/insertUser',
          query: {
	      	id: id
	     }
        })
      }
    },
    created() {
     this.User()
  }
  }
</script>